Skip to content

从内存加载明文模型 - YoloLoadModelMemoryEx

函数简介

从内存加载明文主模型,可选 NCNN .param 与类别名表。

接口名称

YoloLoadModelMemoryEx

DLL 调用

long YoloLoadModelMemoryEx(long ola, long modelData, int modelSize, long ncnnParamData, int ncnnParamSize, long labelData, int labelSize, int modelType, int inferenceType, int inferenceDevice);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
modelData长整数型主模型内存地址
modelSize整数型主模型字节数
ncnnParamData长整数型NCNN .param 地址,无则 0
ncnnParamSize整数型NCNN .param 长度
labelData长整数型类别名称表内存地址;无则 0。传原始文件字节,编码自动识别,见 类别名称表说明
labelSize整数型类别名称表字节长度(精确字节数,不含多余 \0);无则 0
modelType整数型模型类型
inferenceType整数型推理类型
inferenceDevice整数型inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)
text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long YoloLoadModelMemoryEx(long ola, long modelData, int modelSize, long ncnnParamData, int ncnnParamSize, long labelData, int labelSize, int modelType, int inferenceType, int inferenceDevice);

long instance = CreateCOLAPlugInterFace();
YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)

返回值

长整数型:模型句柄,失败返回 0。

注意事项

  • 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
含义
0TensorRT Engine(.engine)
1ONNX(.onnx)
2NCNN(.bin + .param 双文件)
含义
0Detect 目标检测
1Classify 图像分类
2Segment 实例分割
3Pose 姿态估计
4Obb 旋转框检测
  • inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。
  • 缓冲区不得为加密包格式。
  • 推荐 labelBytes = File.ReadAllBytes("labels.txt")labelSize = labelBytes.Length;支持 \| 分隔、多行及 UTF-8/GBK 等编码,见 类别名称表说明